<?php
declare(strict_types=1);

namespace App\Repository\Web;

use App\Repository\BaseRepository;
use App\Model\User;

class UserRepository extends BaseRepository implements UserRepositoryInterface {
    public function __construct(User $user)
    {
        parent::__construct($user);
    }

    public function findByEmail(string $email)
    {
        return $this->findOneBy(['email' => $email]);
    }

    public function findByName(string $name)
    {
        return $this->findOneBy(['name' => $name]);
    }

    public function search(string $keyword)
    {
        return $this->model->where('name', 'like', "%{$keyword}%")
            ->orWhere('email', 'like', "%{$keyword}%")
            ->get()
            ->toArray();
    }
    /**
     * 根据ID查找用户（包含档案）
     */
    public function findWithProfile(int $id)
    {
        return $this->model->with(['profile'])->where('id', $id)->first();
    }
}